package com.googlecode.imanager.client.value.el;

import java.util.Date;

import com.googlecode.imanager.client.value.ValueType;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class Literal extends Expression {

    private static final long serialVersionUID = 1L;

    private final Object value;
    private final ValueType type;
    
    public Literal(String value) {
        this.value = value == null ? "" : this.value;
        this.type = ValueType.TEXT;
    }
    
    public Literal(Character value) {
        this.value = value;
        this.type = ValueType.TEXT;
    }
    
    public Literal(Date value) {
        this.value = value;
        this.type = ValueType.DATE_TIME;
    }
    
    public Literal(Integer value) {
        this.value = value;
        this.type = ValueType.NUMBER;
    }
    
    public Literal(Long value) {
        this.value = value;
        this.type = ValueType.NUMBER;
    }
    
    public Literal(Float value) {
        this.value = value;
        this.type = ValueType.DECIMAL;
    }
    
    public Literal(Double value) {
        this.value = value;
        this.type = ValueType.DECIMAL;
    }
    
    public Literal(Boolean value) {
        this.value = value;
        this.type = ValueType.BOOLEAN;
    }
    
    public Literal(byte value) {
        this.value = value;
        this.type = ValueType.NUMBER;
    }
    
    public Literal(char value) {
        this.value = String.valueOf(value);
        this.type = ValueType.TEXT;
    }
    
    public Literal(short value) {
        this.value = value;
        this.type = ValueType.NUMBER;
    }
    
    public Literal(int value) {
        this.value = value;
        this.type = ValueType.NUMBER;
    }
    
    public Literal(long value) {
        this.value = value;
        this.type = ValueType.NUMBER;
    }
    
    public Literal(float value) {
        this.value = value;
        this.type = ValueType.DECIMAL;
    }
    
    public Literal(double value) {
        this.value = value;
        this.type = ValueType.DECIMAL;
    }
    
    public Literal(boolean value) {
        this.value = value;
        this.type = ValueType.BOOLEAN;
    }
    
    public final Object getSource(){
        return value;
    }
    
    @Override
    public ValueType getValueType() {
        return type;
    }

    @Override
    public Object getValue() {
        return value;
    }

    @Override
    public Expression[] getSubExpressions() {
        return EMPTY_EXPRESSION_ARRAY;
    }

}
